package com.rcmd.cmd;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

import com.rcmd.agent.Proc;

public class FileDataCommand extends Command {
	private long length ;
	private long index ;
	private String fileTarget ;
	private byte[]data ;
	public FileDataCommand(){
		super(Command.FILEDATA) ;
	}
	public FileDataCommand(byte[] data){
		super(Command.FILEDATA) ;

		this.type = Command.FILEDATA;
		this.data = data ;
	}
	public byte[] getData() {
		return data;
	}
	public void setData(byte[] data) {
		this.data = data;
	}
	public long getLength() {
		return length;
	}
	public void setLength(long length2) {
		this.length = length2;
	}
	public long getIndex() {
		return index;
	}
	public void setIndex(int index) {
		this.index = index;
	}
	public String getFileTarget() {
		return fileTarget;
	}
	public void setFileTarget(String fileTarget) {
		this.fileTarget = fileTarget;
	}
	public void setIndex(long index) {
		this.index = index;
	}
	@Override
	protected void read(ObjectInput in) throws IOException,
			ClassNotFoundException {
		// TODO Auto-generated method stub
		this.length = in.readLong();
		this.index = in.readLong() ;
		fileTarget = in.readUTF() ;
		int len = in.readInt() ;
		data = new byte[len] ;
		in.readFully(data) ;
//		Proc.debugPrint("read " +fileTarget);
	}
	@Override
	protected void write(ObjectOutput out) throws IOException {
		// TODO Auto-generated method stub
//		out.flush();
		out.writeLong(length);
		out.writeLong(index);
//		out.flush();
		out.writeUTF(fileTarget == null? "":fileTarget) ;
//		out.flush();
//		System.out.println("write-----------" +fileTarget == null? "":fileTarget);
		out.writeInt(data.length) ;
		out.write(data) ;

		
	}

	
}
